<?php

namespace App\Http\Controllers\Mobile;


use App\Logics\FanLogic;
use App\Logics\UserLogic;


class ProfileController extends BaseController
{
    // 个人资料（必须登录）
    public function initialize()
    {
        parent::initialize();
    }

    // 个人资料
    public function info()
    {
        $info = (new UserLogic())->info($this->myUid);

        return $this->success($info);
    }

    // 完善个人资料
    public function profile()
    {
        $logic = new UserLogic();
        $info  = $logic->profile($this->myUid);
        if($info === false){
            return $this->error($logic->getError());
        }

        return $this->success($info, 'data_improvement_succeeded');
    }

    // 修改密码
    public function password()
    {
        $logic = new UserLogic();
        $info  = $logic->password($this->myUid);
        if($info === false){
            return $this->error($logic->getError());
        }

        return $this->success($info, 'password_modification_succeeded');
    }

    // 注销
    public function cancel()
    {
        $logic = new UserLogic();
        $info  = $logic->cancel($this->myUid);
        if($info === false){
            return $this->error($logic->getError());
        }

        return $this->success([], 'cancel_succeeded');
    }


    ####################################################################################################
    // 关注认证的机构
    public function onFollow()
    {
        $logic = new FanLogic();
        $res   = $logic->onFollow($this->myUid);
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success([], $res ? 'follow_succeeded' : 'unfollow_succeeded');
    }

    // 收藏：各种文章活动
    public function onCollect()
    {
        $logic = new CollectLogic();
        $res   = $logic->onCollect($this->myUid);
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success([], $res ? 'follow_succeeded' : 'unfollow_succeeded');
    }

    // 我的收藏
    public function myCollect()
    {
        $logic = new CollectLogic();
        $res   = $logic->onLists($this->myUid);
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success($res);
    }

    // 我的关注
    public function myFollow()
    {
        $logic = new FanLogic();
        $res   = $logic->onLists($this->myUid);
        if($res === false){
            return $this->error($logic->getError());
        }

        return $this->success($res);
    }

}


